<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon" class="icon-title"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">
                                    <i :class="subItem.icon"></i>
                                    {{ subItem.title }}
                                    </template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                            <i :class="subItem.icon"></i>
                            {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon" class="icon-title"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
export default {
    data() {
        return {
            items: [
                {
                    icon: 'iconfont icon-home',
                    index: '/welcome',
                    title: '系统首页'
                },
                {
                    icon: 'iconfont icon-database-set',
                    index: "/base",
                    title: '基础页面',
                    subs: [
                        {
                            icon: 'iconfont icon-icon-test8',
                            index: '/table',
                            title: '基础表格'
                        },
                        {
                            icon: 'iconfont icon-bell',
                            index: '/tabs',
                            title: 'tab选项卡'
                        },
                        {
                            icon: 'iconfont icon-picture',
                            index: '/icon',
                            title: '自定义图标'
                        },
                        {
                            icon: 'iconfont icon-icon-test37',
                            index: '/form',
                            title: '基本表单'
                        },
                        {
                            icon: 'iconfont icon-icon-test31',
                            index: '/chcarts',
                            title: '基本报表'
                        },
                        {
                            icon: 'iconfont icon-icon-test50',
                            index: '/3',
                            title: '错误处理',
                            subs: [
                                {
                                    icon: 'iconfont icon-icon-test1',
                                    index: '/permission',
                                    title: '权限测试'
                                },
                                {
                                    icon: 'iconfont icon-icon-test63',
                                    index: '/404',
                                    title: '404页面'
                                },
                                {
                                    icon: 'iconfont icon-icon-test62',
                                    index: '/403',
                                    title: '403页面'
                                }
                            ]
                        }
                    ]
                },
                {
                    icon:'iconfont icon-paperplane-fill',
                    index:'/market',
                    title:'营销管理',
                    subs:[
                        {
                            icon:'el-icon-service',
                            index:'/opportunity',
                            title:'销售机会管理'
                        },
                        {
                            icon:'el-icon-c-scale-to-original',
                            index:'/developmentPlan',
                            title:'客户开发计划'
                        },
                    ]
                }
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        },
        collapse(){
            return this.$store.state.collapse
        }
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
.icon-title{
    padding-right: 8px;
}
</style>
